﻿DROP TRIGGER IF EXISTS  `pk_goods_gallery_log`;
CREATE  TRIGGER `pk_goods_gallery_log` AFTER INSERT ON `open_goods_gallery`
  FOR EACH ROW BEGIN
dECLARE pkf varchar(50) DEFAULT "";
sELECT pk_from INTO pkf FROM open_pk_log WHERE pk_from="goods_gallery";
if pkf <> "goods_gallery" then
  INSERT INTO open_pk_log SET pk_from = 'goods_gallery', pk_id = NEW.img_id;
eLSE
   update open_pk_log SET pk_id = NEW.img_id WHERE pk_from = 'goods_gallery';
end if;
end;